<template>
  <div class="changepassword">
    <van-nav-bar
      title="标题"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="oldPassword"
        name="oldPassword"
        label="旧的密码"
        placeholder="旧的密码"
        :rules="[{ required: true, message: '请填写旧的密码' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="新的密码"
        placeholder="新的密码"
        :rules="[{ required: true, message: '请填写新的密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
import { requpdatapassword } from "../../api/user";
export default {
  data() {
    return {
      oldPassword: "",
      password: "",
    };
  },
  computed: {},
  watch: {},

  methods: {
    //返回上一栏
    onClickLeft(){
        Toast('返回');
        this.$router.go(-1); 
    },
    //修改密码
    async onSubmit(values) {
      console.log("submit", values);
      const result = await requpdatapassword(values);
      console.log(result);
      if (result.code == "success") {
        Toast("修改密码成功");
        this.$router.push("/mine");
      } else {
        Toast("原始密码输入错误");
      }
    },
  },
  created() {},
  mounted() {},
  components: {},
};
</script>
<style scoped></style>
